package emailx

import (
	"crypto/tls"
	"net/smtp"

	"github.com/jordan-wright/email"
)

// MailSendCode
// 邮箱验证码发送
func MailSendCode(mailAccount string, MailPassword string, mail string, code string) error {
	e := email.NewEmail()
	e.From = "Get <getcharzhaopan@163.com>"
	e.To = []string{"getcharzp@qq.com"}
	e.Subject = "验证码发送测试"
	e.HTML = []byte("你的验证码为：<h1>" + code + "</h1>")
	err := e.SendWithTLS(
		"smtp.163.com:465",
		smtp.PlainAuth("", mailAccount, MailPassword, "smtp.163.com"),
		&tls.Config{
			// 忽略 https 证书验证
			InsecureSkipVerify: true,
			ServerName:         "smtp.163.com",
		},
	)
	if err != nil {
		return err
	}

	return nil
}
